<?php
	register_sidebar(array(
		'name' => 'sidebar-banners',
		'id' => 'sidebar-banners',
		'description' => 'Sidebar Banners',
		'before_widget' => '<div id="%1$s" class="%2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	));
	add_theme_support('menus');
	add_theme_support('post-thumbnails');

	add_image_size( 'thumb-fotos', 263, 263 );

	//setinhas para o more do excerpt
	function new_excerpt_more( $more ) {
		return '... <span class="veja-mais">&gt;&gt;</span>';
	}
	add_filter('excerpt_more', 'new_excerpt_more');

	//new title with maxlenght
	function new_title($charlength = 80) {
		$title = get_the_title();
		$charlength++;
		
		if(strlen($title) > $charlength) {
			$subex = substr($title,0,$charlength-5);
			$exwords = explode(" ",$subex);
			$excut = -(strlen($exwords[count($exwords)-1]));
			if($excut<0) {
				echo substr($subex,0,$excut);
			} else {
				echo $subex;
			}
			echo "...";
		} else {
			echo $title;
		}
	}


	//new excerpt with maxlenght
	function new_excerpt($charlength = 200) {
		$excerpt = get_the_excerpt();
		$charlength++;
		
		if(strlen($excerpt) > $charlength) {
			$subex = substr($excerpt,0,$charlength-5);
			$exwords = explode(" ",$subex);
			$excut = -(strlen($exwords[count($exwords)-1]));
		if($excut<0) {
			echo substr($subex,0,$excut);
		} else {
			echo $subex;
		}
			echo "<span class='red'>[...]</span>";
		} else {
			echo $excerpt;
		}
	}

	//Youtube get embed
	function parse_youtube_url($url, $return='embed', $width=476, $height=298){ 
		$urls = parse_url($url);
		 
		//expect url is http://youtu.be/abcd, where abcd is video iD
		if($urls['host'] == 'youtu.be'){  
			$id = ltrim($urls['path'],'/'); 
		} 
		//expect  url is http://www.youtube.com/embed/abcd 
		else if(strpos($urls['path'],'embed') == 1){  
			$id = end(explode('/',$urls['path'])); 
		} 
		 //expect url is abcd only 
		else if(strpos($url,'/')===false){ 
			$id = $url; 
		} 
		//expect url is http://www.youtube.com/watch?v=abcd 
		else{
			parse_str($urls['query']);
			$id = $v; 
		}
		//return embed iframe 
		if($return == 'embed'){
			return "<iframe width='$width' height='$height' src='http://www.youtube.com/embed/$id?wmode=transparent&rel=0' frameborder='0' allowfullscreen></iframe>";
		}
		else if($return == 'embed_autoplay'){ 
			return '<object width="'.$width.'" height="' . $height . '"><param name="movie" value="http://www.youtube.com/v/'.$id.'&autoplay=1"></param><param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'.$id.'&autoplay=1" type="application/x-shockwave-flash" width="'.$width.'" height="'.$height.'" allowscriptaccess="always" wmode="transparent" allowfullscreen="true"></embed></object>'; 
		}
		//return normal thumb 
		else if($return == 'thumb'){ 
			return 'http://i1.ytimg.com/vi/'.$id.'/default.jpg'; 
		}
		//return hqthumb 
		else if($return == 'hqthumb'){ 
			return 'http://i1.ytimg.com/vi/'.$id.'/hqdefault.jpg'; 
		}
		// else return id 
		else{
			return $id; 
		}
	}

function admin_add_taxonomy_filters() {
	global $typenow;
 
	if( $typenow == 'atuacoes' ){
 		$taxonomies = array('categoria_de_atuacoes');

		foreach ($taxonomies as $tax_slug) {
			$tax_obj = get_taxonomy($tax_slug);
			$tax_name = $tax_obj->labels->name;
			$terms = get_terms($tax_slug);
			if(count($terms) > 0) {
				echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
				echo "<option value=''>Show All $tax_name</option>";
				foreach ($terms as $term) { 
					echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>'; 
				}
				echo "</select>";
			}
		}
	} else if( $typenow == 'artigos' ){
 		$taxonomies = array('categoria_de_artigos');

		foreach ($taxonomies as $tax_slug) {
			$tax_obj = get_taxonomy($tax_slug);
			$tax_name = $tax_obj->labels->name;
			$terms = get_terms($tax_slug);
			if(count($terms) > 0) {
				echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
				echo "<option value=''>Show All $tax_name</option>";
				foreach ($terms as $term) { 
					echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>'; 
				}
				echo "</select>";
			}
		}
	} else if( $typenow == 'biografia' ){
 		$taxonomies = array('decada');

		foreach ($taxonomies as $tax_slug) {
			$tax_obj = get_taxonomy($tax_slug);
			$tax_name = $tax_obj->labels->name;
			$terms = get_terms($tax_slug);
			if(count($terms) > 0) {
				echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
				echo "<option value=''>Show All $tax_name</option>";
				foreach ($terms as $term) { 
					echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>'; 
				}
				echo "</select>";
			}
		}
	}
}
add_action( 'restrict_manage_posts', 'admin_add_taxonomy_filters' );
